package com.ingress.apcalculator;

import android.content.res.Resources;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.SeekBar;
import android.widget.TextView;

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        SeekBar sb_fields = (SeekBar) findViewById(R.id.sb_fields);
        SeekBar sb_links = (SeekBar) findViewById(R.id.sb_links);
        Resources res = getResources();

        TextView lblMaxFields = (TextView) findViewById(R.id.lbl_max_fields);
        lblMaxFields.setText(String.valueOf(res.getInteger(R.integer.val_max_fields)));

        TextView lblMaxLinks = (TextView) findViewById(R.id.lbl_max_links);
        lblMaxLinks.setText(String.valueOf(res.getInteger(R.integer.val_max_links)));


        sb_fields.setOnSeekBarChangeListener(
                new SeekBar.OnSeekBarChangeListener() {
                    @Override
                    public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                        TextView tvFields = (TextView) findViewById(R.id.tv_fields_value);
                        tvFields.setText(String.valueOf(i));
                        int ap_fields = i * 750;
                        TextView tvSumFields = (TextView) findViewById(R.id.lbl_sum_fields);
                        tvSumFields.setText(String.valueOf(ap_fields));

                        TextView tvSumLinks = (TextView) findViewById(R.id.lbl_sum_links);
                        int ap_links = Integer.parseInt(String.valueOf(tvSumLinks.getText()));

                        TextView tvSum = (TextView) findViewById(R.id.lbl_sum_complete);
                        tvSum.setText(String.valueOf(ap_fields+ap_links));
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {

                    }

                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {

                    }
                }
        );
        sb_links.setOnSeekBarChangeListener(
                new SeekBar.OnSeekBarChangeListener() {
                    @Override
                    public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                        TextView tvLinks = (TextView) findViewById(R.id.tv_links_value);
                        tvLinks.setText(String.valueOf(i));
                        int ap_links = i * 187;
                        TextView tvSumLinks = (TextView) findViewById(R.id.lbl_sum_links);
                        tvSumLinks.setText(String.valueOf(ap_links));

                        TextView tvSumFields = (TextView) findViewById(R.id.lbl_sum_fields);
                        int ap_fields = Integer.parseInt(String.valueOf(tvSumFields.getText()));

                        TextView tvSum = (TextView) findViewById(R.id.lbl_sum_complete);
                        tvSum.setText(String.valueOf(ap_fields+ap_links));


                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {

                    }

                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {

                    }
                }
        );
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}
